Skip to content

DOCSP-37056 eloquent relationships #2747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

ccho-mongodb
Copy link
Contributor

@ccho-mongodb ccho-mongodb commented Mar 5, 2024

JIRA:
https://jira.mongodb.org/browse/DOCSP-37056

Staging:

Eloquent Models Landing Page
Eloquent Models Relationships

Notes for reviewers:

Checklist

  • Add tests and ensure they pass
  • Add an entry to the CHANGELOG.md file
  • Update documentation for new features

@ccho-mongodb ccho-mongodb changed the base branch from 4.2 to 4.1 March 5, 2024 16:27
Copy link
Contributor

@rustagir rustagir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few small things but good work on this challenging material!

Comment on lines 14 to 15
Eloquent models are part of the Laravel Eloquent object-relational
mapping (ORM) framework that enable you to work with a database by using
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: the "that enable" is ambiguous

Suggested change
Eloquent models are part of the Laravel Eloquent object-relational
mapping (ORM) framework that enable you to work with a database by using
Eloquent models are part of the Laravel Eloquent object-relational
mapping (ORM) framework. These models enable you to work with a database by using

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!
I'll use a slightly different structure than suggested since it's the framework rather than the models that relate to the second part.


To learn more about many to many relationships in Laravel, see
`Many to Many <https://laravel.com/docs/{+laravel-docs-version+}/eloquent-relationships#many-to-many>`__
in the Laravel docs.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
in the Laravel docs.
in the Laravel documentation.


To learn more about one to many relationships, see
`One to Many <https://laravel.com/docs/{+laravel-docs-version+}/eloquent-relationships#one-to-many>`__
in the Laravel docs.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
in the Laravel docs.
in the Laravel documentation.

Comment on lines 349 to 350
the parent model instead of keeping foreign key references. This pattern
when you must optimize for one or more of the following requirements:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
the parent model instead of keeping foreign key references. This pattern
when you must optimize for one or more of the following requirements:
the parent model instead of keeping foreign key references. This pattern
is useful if you must optimize for one or more of the following requirements:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching the grammar issue. I think I forgot to change "This" -> "Use this". Rephrasing slightly to match the related fix.

Comment on lines 352 to 355
- Keep associated data together in a single collection
- Perform atomic updates on multiple fields of the document and the associated
data
- Reduce the number of reads required to fetch the data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: based on the way the introduction to this list ends, I think you should change the format of these items

Suggested change
- Keep associated data together in a single collection
- Perform atomic updates on multiple fields of the document and the associated
data
- Reduce the number of reads required to fetch the data
- You must keep associated data together in a single collection
- You must perform atomic updates on multiple fields of the document and the associated
data
- You must reduce the number of reads required to fetch the data

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I decided to convert the verb to a noun by using the gerund.
I think this agrees better with the list introduction.

rustagir
rustagir previously approved these changes Mar 7, 2024
Copy link
Contributor

@rustagir rustagir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few small things but approving - re-request review if you feel it's necessary!

Comment on lines 76 to 77
The following example class shows how to define a ``HasOne`` one to one
relationship between a ``Planet`` and ``Orbit`` model.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: this code example intro and the following one refer to different parts of the code to refer to the relationship as HasOne vs by the method belongsTo(). Perhaps standardize these to either refer to the relationship or the method that creates the relationship?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, will standardize.


A many to many relationship consists of a relationship between two different
model types in which one type of model record can be related to multiple
records of the other type.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: clarify that this relationship applies to both models

Suggested change
records of the other type.
records of the other type and (vice versa or something like that).

Comment on lines +252 to +253
The following section shows an example of how to create a many to many
relationship between model classes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: concision

Suggested change
The following section shows an example of how to create a many to many
relationship between model classes.
The following examples demonstrates how to create a many to many
relationship between model classes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing this out, will use the standardized version (referenced in this comment) instead.

:dedent:

The following sample code shows how ton instantiate a model for each class
and add the relationship between them. Click the :guilabel:`View Output`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: View Output capitalization does not match the GUI VIEW OUTPUT

Suggested change
and add the relationship between them. Click the :guilabel:`View Output`
and add the relationship between them. Click the :guilabel:`View Output`

Comment on lines 386 to 387
The following example class shows how to define an ``embedsMany`` one to many
relationship between a ``SpaceShip`` and ``Cargo`` model:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S; related to earlier comment - decide on a convention to describe this relationship.

Suggested change
The following example class shows how to define an ``embedsMany`` one to many
relationship between a ``SpaceShip`` and ``Cargo`` model:
The following example class shows how to define an ``EmbedsMany`` one to many
relationship between a ``SpaceShip`` and ``Cargo`` model:

Or

Suggested change
The following example class shows how to define an ``embedsMany`` one to many
relationship between a ``SpaceShip`` and ``Cargo`` model:
The following example class shows how to use the ``embedsMany()`` method to define a one to many
relationship between a ``SpaceShip`` and ``Cargo`` model:

Copy link
Contributor Author

@ccho-mongodb ccho-mongodb Mar 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the standardized version mentioned in this comment.

Comment on lines +124 to +128
$spaceship->name = 'The Millenium Falcon';
$spaceship->save();

$cargoSpice = new Cargo();
$cargoSpice->name = 'spice';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixing fictions!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or fictions colliding!

@ccho-mongodb ccho-mongodb marked this pull request as ready for review March 7, 2024 22:10
@ccho-mongodb ccho-mongodb requested a review from a team as a code owner March 7, 2024 22:10
@ccho-mongodb ccho-mongodb requested a review from GromNaN March 7, 2024 22:10
@rustagir rustagir self-requested a review March 7, 2024 22:13
rustagir
rustagir previously approved these changes Mar 7, 2024
Copy link
Contributor

@rustagir rustagir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reapproving!

Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can consider adding unit tests to doc example, that's something do for PHPLIB: https://github.com/mongodb/mongo-php-library/blob/master/tests/DocumentationExamplesTest.php

@ccho-mongodb ccho-mongodb requested a review from GromNaN March 15, 2024 15:55
Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to squash on merge.

@GromNaN GromNaN added the docs label Mar 25, 2024
@GromNaN GromNaN changed the base branch from 4.1 to docs-rewrite March 25, 2024 16:26
@GromNaN GromNaN changed the base branch from docs-rewrite to 4.1 March 25, 2024 16:59
@ccho-mongodb ccho-mongodb merged commit 2117c2c into mongodb:4.1 Mar 25, 2024
@ccho-mongodb ccho-mongodb deleted the DOCSP-37056-eloquent-relationships branch March 25, 2024 21:08
This was referenced Mar 25, 2024
jmikola pushed a commit that referenced this pull request Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants